package com.h.service.impl;

import com.h.javabean.Role;
import com.h.mapper.RoleMapper;
import com.h.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

@Service
public class RoleServiceImpl implements RoleService {
    @Autowired
    RoleMapper roleMapper;

    @Override
    public List<Role> findAll() {
        return roleMapper.selectAll();
    }

    @Override
    @Transactional
    public void delete(int id) {
        roleMapper.deleteR_PById(id);
        roleMapper.deleteById(id);
    }
    @Override
    public void add(Role role) {
        roleMapper.insert(role);
    }

    @Override
    public Role findRole_Permission(int id) {
        return roleMapper.selectRole_Permission(id);
    }

    @Override
    public void edit(Role role) {
        roleMapper.update(role);
    }

    @Override
    @Transactional
    public void editPermission(int rid, List<Integer> ids) {
        roleMapper.deleteR_P(rid);
        roleMapper.insertR_P(rid,ids);
    }
}